package Game;

import java.awt.Graphics2D;
import java.util.LinkedList;

import Game.Ally.AllyState;

public class AllyManager
{
	static LinkedList<PoliticAlly> politics;
	static LinkedList<CPI> CPIs;
	
	private AllyManager() {}
	
	static boolean added_removed;
	
	public static void Setup()
	{
		politics = new LinkedList<PoliticAlly>();
		CPIs = new LinkedList<CPI>();
	}
	
	public static void AddPolitic(PoliticAlly ally)
	{
		System.out.print("Aliado");
		politics.addFirst(ally);
		System.out.println(" adicionado");
		added_removed = true;
	}
	
	public static void AddCPI(CPI ally)
	{
		System.out.print("Aliado");
		CPIs.addFirst(ally);
		System.out.println(" adicionado");
		added_removed = true;
	}
	
	public static void Update()
	{
		if(added_removed)
			added_removed = false;
		
		if(CPIs != null)
		{
			for(CPI cpi : CPIs)
			{
				cpi.Update();
				
				if(cpi.state == AllyState.DEAD)
				{
					CPIs.remove(cpi);
				}
				if(cpi.add_remove)
				{
					added_removed = true;
					break;
				}
			}
		}
		
		if(politics != null)
		{
			for(PoliticAlly politic : politics)
			{
				if(added_removed)
					break;
				
				politic.Update();
				
				if(politic.state == AllyState.DEAD)
				{
					politics.remove(politic);
					break;
				}
			}
		}
	}
	
	public static void Draw(Graphics2D g2d)
	{
		if(politics != null)
		{
			for(PoliticAlly politic : politics)
			{
				politic.Draw(g2d);
			}
		}
		
		if(CPIs != null)
		{
			for(CPI cpi : CPIs)
			{
				cpi.Draw(g2d);
			}
		}
	}
}